package com.haixee.parkdemo.auth.service.impl;

import com.haixee.parkdemo.auth.dao.DataScopeCustomMapper;
import com.haixee.parkdemo.auth.dao.FieldRuleCustomMapper;
import com.haixee.parkdemo.auth.dao.FieldRuleMapper;
import com.haixee.parkdemo.auth.dao.FieldRuleShowCustomMapper;
import com.haixee.parkdemo.auth.entity.dto.DataScopeDTO;
import com.haixee.parkdemo.auth.model.DataScope;
import com.haixee.parkdemo.auth.model.FieldRule;
import com.haixee.parkdemo.auth.model.FieldRuleShow;
import com.haixee.parkdemo.auth.service.DataAccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataAccessServiceImpl implements DataAccessService {

    @Autowired
    private DataScopeCustomMapper dataScopeCustomMapper;

    @Autowired
    private FieldRuleCustomMapper fieldRuleCustomMapper;

    @Autowired
    private FieldRuleShowCustomMapper fieldRuleShowCustomMapper;

    @Autowired
    private FieldRuleMapper fieldRuleMapper;

    @Override
    public DataScope getByAclId(Integer aclId) {
        return dataScopeCustomMapper.selectByAclId(aclId);
    }

    @Override
    public List<FieldRule> getFieldRules(Integer aclId, List<String> fields) {
        return fieldRuleCustomMapper.selectByAclIdAndNameIn(aclId, fields);
    }

    @Override
    public List<DataScopeDTO> getByModuleId(Integer aclId) {

        return dataScopeCustomMapper.selectByAclParentId(aclId);
    }

    @Override
    public void updateScore(DataScope dataScope) {
        dataScopeCustomMapper.updateByAclId(dataScope.getAclId(), dataScope.getSelfAccess(), dataScope.getSameLevelAccess(), dataScope.getUpLevelAccess());
    }

    @Override
    public List<FieldRuleShow> getFieldRuleShow(Integer aclId) {
        return fieldRuleShowCustomMapper.selectByAclId(aclId);
    }

    @Override
    public void addFieldRule(FieldRule rule) {
        fieldRuleMapper.insertSelective(rule);
    }

    @Override
    public void updateFieldRule(FieldRule rule) {
        fieldRuleMapper.updateByPrimaryKeySelective(rule);
    }
}
